# 1.导包
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 2.打开浏览器（创建浏览器驱动对象）
path = r"D:\tools\python\chromedriver.exe"
ser = Service(executable_path=path)  # Chrome浏览器驱动服务对象
driver = webdriver.Chrome(service=ser)  # 打开Chrome浏览器
driver.maximize_window()
# 3.输入网址
driver.get("http://121.43.169.97:8082/")
# 4.页面操作
# 4.0 登录
driver.find_element(By.ID,'username').send_keys('admin')
driver.find_element(By.ID,'password').send_keys('HM_2025_test')
driver.find_element(By.ID,'valicode').send_keys('8888')
driver.find_element(By.CLASS_NAME,'login-button').click()
time.sleep(3)
driver.find_element(By.XPATH,'/html/body/div[1]/div[2]/ul/li[2]/a').click()
driver.find_element(By.XPATH,'//*[@id="sidebar"]/ul/li[5]/a/span').click()
time.sleep(1)
driver.find_element(By.XPATH,'//*[@id="sidebar"]/ul/li[5]/ul/li[2]/a').click()
time.sleep(1)
# 2. 定位 iframe（通过 id="iframe_box"）
iframe_element = driver.find_element(By.ID, "iframe_box")

# 3. 切换到 iframe 内部
driver.switch_to.frame(iframe_element)

driver.find_element(By.XPATH,'/html/body/div[2]/div[3]/table/tbody/tr[1]/td[1]').click()
time.sleep(1)

driver.find_element(By.XPATH,'/html/body/div[2]/div[2]/ul/li[1]/a/span').click()
time.sleep(1)


num = driver.find_element(By.XPATH, "/html/body/div[5]/div[1]/iframe")

# 3. 切换到 iframe 内部
driver.switch_to.frame(num)
driver.find_element(By.XPATH,'/html/body/div[2]/form/table/tbody/tr[5]/td[2]/div/label[1]/span').click()
time.sleep(1)
driver.find_element(By.XPATH,'/html/body/div[2]/form/table/tbody/tr[6]/td[2]/div/textarea').send_keys('1321546465456465')
time.sleep(1)
driver.find_element(By.XPATH,'/html/body/div[2]/form/table/tbody/tr[7]/td[2]/div/ul/li[1]/input').send_keys('8888')
time.sleep(1)
driver.find_element(By.XPATH,'/html/body/div[2]/form/table/tbody/tr[8]/td[2]/input[1]').click()





# # 4.1 切换身份：借款人 //em[text()="借款账户"]
# # driver.find_element(By.XPATH, "//em[text()='借款账户']").click()
# WebDriverWait(driver, 10).until(
#     EC.visibility_of_element_located((By.XPATH, "//em[text()='借款账户']"))
# ).click()
# # 4.2 点击申请额度
# # driver.find_element(By.LINK_TEXT, "申请额度").click()
# WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.LINK_TEXT, "申请额度"))).click()
# # 4.3 填写申请信息
# WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "amount_account"))).send_keys("200000")
# driver.find_element(By.NAME, "remark").send_keys("测试账号申请额度")
# driver.find_element(By.ID, "verifycode").send_keys("8888")
# driver.find_element(By.CSS_SELECTOR, ".btn-submit.btn-md").click()
# 5.等待2秒
time.sleep(2)
# 6.退出浏览器
driver.quit()